from manim import *

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        self.camera.frame.scale(1.5)
        self.camera.frame.move_to([0,0.9,0])
        axes=Axes(
            x_range=[-5,5],
            y_range=[-5,5],
            x_length=10,
            y_length=10,
            tips=False
        )
        graph = ImplicitFunction(
            lambda x, y: x**2+y**2-16,
            color=YELLOW
        )
        m,o=[1,2,0],ORIGIN
        a,b,c=[-1.97,3.48,0],[3.97,0.52,0],[3.2,6.4,0]
        d12=Dot(m)
        self.add(axes,graph,d12)
        self.add(Circle(4),
            Line(a,b),
            Line(a,c),
            Line(b,c),
            Line(o,a),
            Line(o,b),
            MathTex('M(1,2)').next_to(m),
            MathTex('O').next_to(o,DL),
            MathTex('A').next_to(a,UL),
            MathTex('B').next_to(b),
            MathTex('C').next_to(c)
        )

class p2(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        self.camera.frame.scale(1.5)
        self.camera.frame.move_to([0,0.9,0])
        axes=Axes(
            x_range=[-5,5],
            y_range=[-5,5],
            x_length=10,
            y_length=10,
            tips=False
        )
        graph = ImplicitFunction(
            lambda x, y: x**2+y**2-16,
            color=YELLOW
        )
        m,o=[1,2,0],ORIGIN
        a,b,c=[-1.97,3.48,0],[3.97,0.52,0],[3.2,6.4,0]
        d12=Dot(m)
        self.add(axes,graph,d12)
        self.add(Circle(4),
            Line(a,b),
            Line(a,c),
            Line(b,c),
            Line(o,a),
            Line(o,b),
            MathTex('M(1,2)').next_to(m),
            MathTex('O').next_to(o,DL),
            MathTex('A').next_to(a,UL),
            MathTex('B').next_to(b),
            MathTex('C').next_to(c)
        )
        # p2
        self.add(
            Line(o,m),
            Line(m,c),
            Angle(Line(m,a),Line(m,o),elbow=True),
            Angle(Line(a,o),Line(a,c),elbow=True),
            Angle(Line(b,c),Line(b,o),elbow=True),
            MathTex('4').move_to([-1.2,1.6,0]),
            MathTex(r'\sqrt{5}').move_to([0.8,1,0]),
        )